﻿using B.S.DataBase.MyProject.Domain.基础设置;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
<<<<<<<< HEAD:MedicalPCTerminal.Read.API/Appcation/CommandHandlers/BasicSettingsCommandHandler/QueryInstitutionCommandHandler.cs
using MedicalPCTerminal.Read.API.Appcation.Commands.BasicSettingsCommand;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.BasicSettingsCommandHandler
========
using MedicalPCTerminal.Read.API.Appcation.Commands.基础设置;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.基础设置
>>>>>>>> parent of fe317f5 (修改命名空间):MedicalPCTerminal.Read.API/Appcation/CommandHandlers/基础设置/QueryInstitutionCommandHandler.cs
{
    /// <summary>
    /// 处理
    /// </summary>
    public class QueryInstitutionCommandHandler : IRequestHandler<QueryInstitutionCommand, APIResult<List<Institution>>>
    {
        /// <summary>
        /// sqlsugar
        /// </summary>
        private readonly SqlSugarContext sqlSugar;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="sqlSugar"></param>
        public QueryInstitutionCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }
        /// <summary>
        /// 处理机构显示命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<Institution>>> Handle(QueryInstitutionCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<Institution>> result = new APIResult<List<Institution>>();
                var entity = sqlSugar.db.Queryable<Institution>().ToList();
                if (!string.IsNullOrEmpty(request.InstitutionName))
                {
                    entity = entity.Where(x => x.InstitutionName.Contains(request.InstitutionName)).ToList();
                }
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = entity;
                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
